package com.cskaoyan.market.service;

import com.cskaoyan.market.db.domain.MarketCommentExample;
import com.cskaoyan.market.db.mapper.MarketCommentMapper;
import com.cskaoyan.market.db.mapper.MarketCommentUserMapper;
import com.cskaoyan.market.vo.CommentVo;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author Wisteria
 * @version 1.0
 * @description: 评论的具体实现类
 */
@Service
public class WxCommentServiceImpl implements WxCommentService {
    @Autowired
    MarketCommentUserMapper marketCommentUserMapper;
    @Autowired
    MarketCommentMapper marketCommentMapper;

    /**
     * @description: 分页展示评论详情
     */
    @Override
    public List<CommentVo> list(Integer page, Integer limit, Integer valueId, Byte type) {
        PageHelper.startPage(page, limit);
        List<CommentVo> commentVoList = marketCommentUserMapper.selectByValueId(valueId, type);
        return commentVoList;
    }

    /**
     * @description: 展示总数
     */
    @Override
    public Map<String, Long> count(Integer valueId, Byte type) {
        MarketCommentExample commentExample = new MarketCommentExample();
        commentExample.or().andDeletedEqualTo(false).andValueIdEqualTo(valueId).andTypeEqualTo(type);
        long commentCount = marketCommentMapper.countByExample(commentExample);
        MarketCommentExample picExample = new MarketCommentExample();
        picExample.or().andDeletedEqualTo(false).andValueIdEqualTo(valueId).andTypeEqualTo(type).andHasPictureEqualTo(true);
        long picCount = marketCommentMapper.countByExample(picExample);
        HashMap<String, Long> map = new HashMap<>();
        map.put("allCount", commentCount);
        map.put("hasPicCount", picCount);
        return map;
    }
}
